package com.sx.manage.controller.file;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.sx.manage.controller.base.MBaseController;
import com.sx.manage.service.file.MCompanyCertificateWebServiceImpl;
import com.sx.manage.servlet.ViewAndModel;
import com.sx.model.manage.mybatis.form.file.MCertificateAddressForm;
import com.sx.model.manage.mybatis.vo.file.MCertificateAddressVO;
import com.sx.model.manage.mybatis.vo.result.ResultBooleanVO;
import com.sx.model.manage.mybatis.vo.result.ResultListVO;
import com.sx.model.manage.mybatis.vo.result.ResultUploadVO;

/**
 * 证件类型地址controller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/company/certificate")
public class MCompanyCertificateController extends MBaseController {
	/**
	 * 日志
	 */
	private Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Resource(name="companyCertificateWebServiceImpl")
	private MCompanyCertificateWebServiceImpl companyCertificateWebServiceImpl;
	/** 跳转到证件上传界面**/
	@RequestMapping(value = "/index/{company_id}")
	public ViewAndModel certificate_index(@PathVariable Long company_id) {
		log.info("跳转到证件上传界面");
		return companyCertificateWebServiceImpl.certificate_index(new ViewAndModel(request, cache),company_id);
	}
	/** 跳转到证件上传界面**/
	@RequestMapping(value = "/toAdd/{company_id}")
	public ViewAndModel certificate_toAdd(@PathVariable Long company_id) {
		log.info("跳转到证件上传界面");
		return companyCertificateWebServiceImpl.certificate_toAdd(new ViewAndModel(request, cache),company_id);
	}
	/** 跳转到证件上传界面**/
	@RequestMapping(value = "/toEdit/{id}")
	public ViewAndModel certificate_toEdit(@PathVariable Long id) {
		log.info("跳转到证件上传界面");
		return companyCertificateWebServiceImpl.certificate_toEdit(new ViewAndModel(request, cache),id);
	}
	/**保存证件信息*/
	@RequestMapping(value = "/save")
	@ResponseBody
	public ResultBooleanVO certificate_save(@RequestBody MCertificateAddressForm form) {
		log.info("保存证件地址信息form={}",form);
		return companyCertificateWebServiceImpl.certificate_save(form,this.loginConsumer());
	}
	/**保存证件信息*/
	@RequestMapping(value = "/update")
	@ResponseBody
	public ResultBooleanVO certificate_update(@RequestBody MCertificateAddressForm form) {
		log.info("保存证件地址信息form={}",form);
		return companyCertificateWebServiceImpl.certificate_update(form,this.loginConsumer());
	}
	/**查询分页数据列表*/
	@RequestMapping("/page")
	@ResponseBody
	public ResultListVO<MCertificateAddressVO> certificate_page(MCertificateAddressForm form) {
		log.info("查询分页数据列表form={}",form);
		return companyCertificateWebServiceImpl.certificate_page(form);
	}
	/**图片上传*/
	@RequestMapping(value = "/upload")
	@ResponseBody
	public ResultUploadVO<String> upload(@RequestParam(value = "files", required = false) MultipartFile file, HttpServletRequest request) {
		log.info("证件图片上传file={}",file);
		return companyCertificateWebServiceImpl.upload(file, request);
	}
	

}
